package com.example.utils.MQ;

import com.example.utils.MyOSSUtil;
import com.example.vehicle.dao.VehicleMapper;
import com.rabbitmq.client.Channel;
import org.apache.http.entity.ContentType;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

@Component
public class UploadConsumer {

    @Autowired
    VehicleMapper vehicleMapper;

    @RabbitListener(queues = UploadBean.LWH_UPLOAD_QUEUE_NAME)
    public void UploadMan(Message message, Channel channel) throws IOException {
        final byte[] body = message.getBody();
        InputStream inputStream = new ByteArrayInputStream(body);
        MultipartFile file = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);
        MyOSSUtil myOSSUtil = new MyOSSUtil();
        final String s = myOSSUtil.uploadFile(file);
//        vehicleMapper.uploadImg(s);
        System.out.println("-----------我接收到了文件-----------");
        System.out.println("-----------我接收到了文件-----------");
        System.out.println("-----------我接收到了文件-----------");
    }

}
